import { Button, Form } from 'antd';
import React, { useEffect } from 'react';
import AddDirModal from './addDirModal';

import { ContentDirListItem } from '@/types/contentMng/contentDirectory';

interface IProps {
  open: boolean;
  onClose: (options?: { isRefresh: boolean }) => void;
  data: ContentDirListItem;
}

const AddFirstLevelDir = (props: IProps) => {
  const { open, onClose, data } = props;

  const [form] = Form.useForm();
  useEffect(() => {
    if (!data) return;
    form?.setFieldsValue({
      contents: data.contents,
      catalogueName: data.catalogueName,
    });
  }, [data]);

  const onCancel = () => {
    form.resetFields();
    onClose();
  };

  return (
    <AddDirModal
      title="目录详情"
      open={open}
      footer={[
        <Button type="default" onClick={onCancel}>
          关闭
        </Button>,
      ]}
      formProps={{ form, disabled: true }}
      disabled={true}
      fieldsList={data?.contents || []}
    />
  );
};

export default AddFirstLevelDir;
